
#ifndef CHAPTER15_ERROR5_H_
#define CHAPTER15_ERROR5_H_

#include <iostream>
#include <cmath>
#include <string>
#include "chapter15_exc_mean.h"

class demo
{
private:
	string word;
public:
	demo(const string & str)
	{
		word = str;
		cout << "demo " << word << " created\n";
	}
	~demo()
	{
		cout << "demo " << word << " destroyed\n";
	}
	void show() const
	{
		cout << "demo " << word << " live!\n";
	}
};

//function prototypes
double hmean(double a, double b)
{
	if (a == -b)
		throw bad_hmean(a, b);
	return 2.0*a*b / (a + b);
}

double gmean(double a, double b)
{
	if (a < 0 || b < 0)
		throw bad_gmean(a, b);
	return sqrt(a*b);
}

double means(double a, double b)
{
	double am, hm, gm;
	demo d2("found in means()");
	am = (a + b) / 2.0;			//arithmetic mean
	try
	{
		hm = hmean(a, b);
		gm = gmean(a, b);
	}
	catch (bad_hmean & bg)		//start of catch block
	{
		bg.mesg();
		cout << "Caught in means()\n";
		throw;
	}
	d2.show();
	return (am + hm + gm) / 3.0;
}

#endif